<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <script type="text/javascript">
    //使用Promise#then同时处理多个异步请求
    function getURL(url) {
        return new Promise(function(resolve, reject) {
            var req = new XMLHttpRequest();
            req.open('GET', url, true);
            req.onlaod = function() {
                if (req.status === 200) {
                    resolve(req.responseText);
                } else {
                    reject(new Error(req.statusText));
                }
            }
            req.onerror = function() {
                reject(new Error(req.statusText));
            }
            req.send();
        });
    }
    var request = {
        comment: function getComment() {
            return getURL('http://azu.github.io/promises-book/json/comment.json').then(JSON.parse);
        },
        people: function getPeople() {
            return getURL('http://azu.github.io/promises-book/json/people.json').then(JSON.parse);
        }
    };
    function main() {
    	return Promise.all([request.comment(),request.people()]);
    }
    main().then(function(value) {
    	console.log(value);
    }).catch(function(error) {
    	console.log(error);
    });
    </script>
</head>

<body>
</body>

</html>
